import math

def word_to_number(word):
    numbers = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'}
    return numbers.get(word)

def is_prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    max_divisor = math.isqrt(n)
    for d in range(3, max_divisor + 1, 2):
        if n % d == 0:
            return False
    return True

def find_nearest_prime_number(words):
    number_str = ''.join([word_to_number(word) for word in words if word_to_number(word) is not None])
    
    if not number_str.isdigit() or len(number_str) != 3 or None in [word_to_number(word) for word in words]:
        print("Wrong input")
        return
    
    number = int(number_str)
    
    if is_prime(number):
        print(number)
        return
    
    lower = number - 1
    upper = number + 1
    while True:
        if is_prime(lower):
            print(lower)
            return
        elif is_prime(upper):
            print(upper)
            return
        lower -= 1
        upper += 1

input_words = input("Введите три слова: ").split()
find_nearest_prime_number(input_words)
